package cm367;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

@ManagedBean
public class Venue {
	private String code;
	private String name;
	private double area;
	private int capacity;
	private String description;
	private double cost;
	private boolean newrec = false;
	
	private byte selectperiod;
	private Date selectdate;

	@ManagedProperty(value = "#{venueService}")
	private VenueService venueservice;

	@ManagedProperty(value = "#{bookingDetail}")
	private BookingDetail bookingdetail;

	public Venue() {

	}	

	public byte getSelectperiod() {
		return selectperiod;
	}



	public void setSelectperiod(byte selectperiod) {
		this.selectperiod = selectperiod;
		System.out.println(selectperiod);
	}



	public Date getSelectdate() {
		return selectdate;
	}



	public void setSelectdate(Date selectdate) {
		this.selectdate = selectdate;
		System.out.println(selectdate.toString());
	}



	public BookingDetail getBookingdetail() {
		return bookingdetail;
	}

	public void setBookingdetail(BookingDetail bookingdetail) {
		this.bookingdetail = bookingdetail;
	}

	public Venue(String str) {
		str = str.replace('|', '\t');
		String[] tmp = str.split("\t");
		this.code = tmp[0];
		this.name = tmp[1];
		this.area = Double.parseDouble(tmp[2]);
		this.capacity = Integer.parseInt(tmp[3]);
		this.description = tmp[4];
		this.cost = Double.parseDouble(tmp[5]);
	}

	public boolean getNewrec() {
		return newrec;
	}

	public void setNewrec(boolean newrec) {
		this.newrec = newrec;
	}

	public double getCost() {
		return cost;
	}

	public void setCost(double cost) {
		this.cost = cost;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		if (!newrec) {
			Venue v = venueservice.findVenuebyCode(code);
			this.code = v.code;
			this.name = v.name;
			this.area = v.area;
			this.capacity = v.capacity;
			this.description = v.description;
			this.cost = v.cost;

			bookingdetail.setBookVenus(v.code);
			bookingdetail.setVenusDesc(v.name);
			bookingdetail.setVenusPrice(v.cost);
		} else
			this.code = code;
	}

	public void updateVenue() {
		Venue v = null;
		if (!newrec) {
			v = venueservice.findVenuebyCode(code);
			v.name = this.name;
			v.area = this.area;
			v.capacity = this.capacity;
			v.description = this.description;
			v.cost = this.cost;
		} else {
			v = new Venue();
			v.code = this.code;
			v.name = this.name;
			v.area = this.area;
			v.capacity = this.capacity;
			v.description = this.description;
			v.cost = this.cost;
			venueservice.getVenuelist().add(v);
		}

	}

	public void removeVenue() {
		Venue v = venueservice.findVenuebyCode(code);
		venueservice.getVenuelist().remove(v);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getArea() {
		return area;
	}

	public void setArea(double area) {
		this.area = area;
	}

	public int getCapacity() {
		return capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public VenueService getVenueservice() {
		return venueservice;
	}

	public void setVenueservice(VenueService venueservice) {
		this.venueservice = venueservice;
	}
}
